/*
 * 作者：姚俊
 * 功能：审核项目的action
 * 日期：2015-05-29
 */
package admin.action.checkFruits;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.mail.MessagingException;
import javax.mail.internet.AddressException;

import admin.email.SendEmail;
import admin.service.fruits.ProjectService;
import teacher.bean.Award;
import teacher.bean.Flow;
import teacher.bean.Project;
import teacher.bean.Teacher;
import teacher.service.project;
import teacher.service.flow;
import teacher.service.teacher;

public class ProjectCheckedAction {
	
	private Project project;

	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}
	
	
	public String execute()
	{
		Project pro=new ProjectService().getProject(this.getProject());
		Teacher tea=new teacher().SelectTeaByPro(pro);
		if(tea!=null)
		{
			pro.setState(5);
			new ProjectService().updateProject(pro, this.getProject());
			/*try {
				SendEmail.send_email(tea.getMail(), "项目审核成功","恭喜您"+tea.getName()+",您的项目已经被管理员审核成功！");
			} catch (AddressException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (MessagingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}*/
		}
		
//		流程管理开始
		Project a=new Project();
		a=new project().selectProjectById(this.getProject().getProId());
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Flow f=new Flow();
		f.setFruitId(a.getProId());
		f.setFruitKind(4);
		f.setDirDo(2);
		f.setDirTime(df.format(new Date()));
		f.setSubDo(0);
		f.setSubTime(df.format(new Date()));
		f.setTeaDo(2);
		f.setTeaTime(df.format(new Date()));
//		流程管理结束
		if(new flow().insertFlow(f)){
			return "succ";
		}else{
			return "succ";
		}
	}

}
